{
  "properties" : { },
  "id" : "copy1745560566027d58621",
  "script" : null,
  "groupId" : "b49fd3aa7ab944ca938fd37f3364f0ba",
  "name" : "B52查询气象站实时天气情坐标查询混合",
  "createTime" : 1745560633060,
  "updateTime" : null,
  "lock" : null,
  "createBy" : "admin",
  "updateBy" : null,
  "path" : "/wsstationweathermix",
  "method" : "GET",
  "parameters" : [ {
    "name" : "time",
    "value" : "",
    "description" : "数据可以按找小时获取  yyyy-MM-ddTHH:00:00   不填写取最终数据",
    "required" : false,
    "dataType" : "String",
    "type" : null,
    "defaultValue" : null,
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  }, {
    "name" : "lon",
    "value" : "126.35",
    "description" : "经度",
    "required" : true,
    "dataType" : "String",
    "type" : null,
    "defaultValue" : null,
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  }, {
    "name" : "lat",
    "value" : "43.56",
    "description" : "纬度",
    "required" : true,
    "dataType" : "String",
    "type" : null,
    "defaultValue" : null,
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  }, {
    "name" : "num",
    "value" : "5",
    "description" : "按照距离取最近的多条数据  参数为空时仅取一条",
    "required" : false,
    "dataType" : "String",
    "type" : null,
    "defaultValue" : null,
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  }, {
    "name" : "maxdislimit",
    "value" : "30",
    "description" : "最大距离限制 超过距离数据无法查询 不传不限制数据",
    "required" : false,
    "dataType" : "String",
    "type" : null,
    "defaultValue" : null,
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  }, {
    "name" : "stationtype",
    "value" : "",
    "description" : "站点类型  1. 国家站  2. 区域站 3. 火险监测站(海康)  4:和风天气",
    "required" : false,
    "dataType" : "String",
    "type" : null,
    "defaultValue" : null,
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  } ],
  "options" : [ ],
  "requestBody" : "",
  "headers" : [ ],
  "paths" : [ ],
  "responseBody" : "{\n    \"code\": 0,\n    \"message\": \"success\",\n    \"data\": [\n        {\n            \"distance\": 17095.15232771,\n            \"stationkey\": \"101060203\",\n            \"timebase\": \"2025-04-25T00:00:00.000+00:00\",\n            \"pres\": 981,\n            \"pres_sea\": null,\n            \"temp\": 7,\n            \"temp_max\": null,\n            \"temp_min\": null,\n            \"humi\": 47,\n            \"humi_min\": null,\n            \"prec\": 0,\n            \"win_10_dir\": 225,\n            \"win_10_vel\": 17,\n            \"win_inst_dir\": null,\n            \"win_inst_vel\": null,\n            \"snow\": null,\n            \"wep_now\": null,\n            \"month\": \"202504\",\n            \"wep_txt\": \"多云\",\n            \"stationname\": \"永吉\",\n            \"lon\": 126.501625,\n            \"lat\": 43.667416,\n            \"norainday\": 12,\n            \"time\": \"2025-04-25 08:00:00\",\n            \"orgid\": \"220002021\",\n            \"orgname\": \"吉林市\",\n            \"ffid\": \"55 = 27 + 0 + 9 + 19 C降雨指数=1 C1春防秋防指数=0\",\n            \"firelevel\": \"1\"\n        }\n    ],\n    \"timestamp\": 1745545192090,\n    \"executeTime\": 6846\n}",
  "description" : null,
  "requestBodyDefinition" : null,
  "responseBodyDefinition" : null
}
================================
/**
 *   按照机构号码查询、
 *  @param   orgid  系统机构
 *  @param   time        时间格式数据可以按找小时获取  yyyy-MM-ddTHH:00:00   不传查最新 传查指定时间  必须传入整点数据
 *  @param   lon  lat 坐标
 * 
 *     
     left join fx_station_norainday nr on  nr.stationkey = t1.stationkey and DATE(t1.timeBase) = nr.date
 */
import com.mingda.weathermagiccenter.utils.WeatherDeal;
import 'java.lang.System' as System;
var sql = """
with
cr as
( select distinct ws_station.* from ws_station,ws_station_data
where  ws_station.stationkey = ws_station_data.stationkey
    <if test="time != null and time != ''\" > and TO_TIMESTAMP(replace(#{time},'T',' '), 'YYYY-MM-DD HH24:MI:SS') = ws_station_data.timebase </if>
    <else>and date(ws_station_data.timebase) = CURRENT_DATE</else>
) 

    select stationkey,  ST_Distance( ST_MakePoint(CAST(lon AS float8), CAST(lat AS float8))::geography,  ST_MakePoint(CAST(#{lon} AS float8),CAST(#{lat} AS float8))::geography )  AS distance
    from cr  
    where 1 = 1 
     and stationtype != '2'
     <if test="stationtype != null and stationtype != ''" > and stationtype = #{stationtype} </if>
     <if test="maxdislimit != null and maxdislimit != ''\" > 
     and   ST_Distance( ST_MakePoint(CAST(lon AS float8), CAST(lat AS float8))::geography,  ST_MakePoint(CAST(#{lon} AS float8),CAST(#{lat} AS float8))::geography )  <=
      CAST(#{maxdislimit} AS float8) * 1000
      </if>
    order by distance 
    LIMIT <if test="num != null and num != ''\" >CAST(#{num} AS INT)</if> 
        <else>1</else>
     ;
"""
 

 var nereststation = [];
 //var distance ="";
//查询最近的站点
 var result =  db.select (sql);
 if(result.size() > 0){

     for(item in result){
        nereststation.add(item.stationkey);
     }
     System.out.println("------------------"+nereststation);
     // distance =  result.get(0).distance;
 }
 else{
     return null;
 }

// 获得最近气象站点的数据 ,${distance} as distance
var sql2 = """
    select ST_Distance( ST_MakePoint(CAST(lon AS float8), CAST(lat AS float8))::geography,  ST_MakePoint(CAST(#{lon} AS float8),CAST(#{lat} AS float8))::geography )  AS distance,t1.*,s.stationname,s.lon,s.lat,nr.norainday,to_char(t1.timebase, 'YYYY-MM-DD HH24:MI:SS') as time,s.orgid,s.orgname  from ws_station_data t1  
    join ws_station s on t1.stationkey = s.stationkey

    join( select stationKey ,max(timeBase) as latest_timestamp 
    from ws_station_data
    where 1 = 1 
    <if test="time != null and time != ''\" > and TO_TIMESTAMP(replace(#{time},'T',' '), 'YYYY-MM-DD HH24:MI:SS') = timeBase </if>


      and stationKey in 
    <foreach collection="nereststation" item="id" open="(" close=")" separator=",">
		'${id}'
    </foreach>
  
    group by stationKey
    )  t2 on t1.stationKey = t2.stationKey and t1.timeBase = t2.latest_timestamp

    left join fx_norainday nr on  nr.stationkey = t1.stationkey and DATE(t1.timeBase) = nr.date   
 
"""
//order by distance 

    var result = db.select (sql2);

return WeatherDeal.getFireLevel(result);
//return WeatherDeal.getFireLevel(result);

 